package com.bnz.controller;

import com.bnz.entity.Users;
import com.bnz.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreFilter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("con")
public class Ucontroller {
    // 注入service
    @Autowired
    private UsersService usersService;

    @RequestMapping("/user/wel")
    public String wel(){
        return "welcome";
    }

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @GetMapping("/user/findAll")
    @ResponseBody // 将java对象转为json格式的数据
    public List<Users> findAll(){
        List<Users> users = new ArrayList<>();
        users.add(new Users(1,"ab","test1"));
        users.add(new Users(2,"ac","test2"));
        return users;
    }

    @GetMapping("/user/find")
    @ResponseBody
    @PreFilter(value = "filterObject.id % 2 == 0")
    // @RequestBody // 讲前端发来的消息放进javabean
    public List<Users> find(@RequestBody  List<Users> users){
        System.out.println("ids = " + users);
        return users;
    }
}
